﻿#include <iostream>
#include <opencv2\opencv.hpp>

using namespace cv;
using namespace std;

int main()
{
    std::cout << "test_sobel\n";
    cv::Mat img_org = cv::imread(".\\lena.jpg");
    cv::Mat img_gaussian;
    cv::Mat img_gray;
    cv::Mat xgrad0, ygrad0;
    cv::Mat xgrad1, ygrad1;
    cv::Mat laplace;
    

    GaussianBlur(img_org, img_gaussian, Size(3, 3), 0, 0, 0);
    cvtColor(img_gaussian, img_gray, CV_BGR2GRAY);
    //cv::imshow("gaussian&gray", img_gray);

    Scharr(img_gray, xgrad0, CV_16S, 1, 0, 3);
    Scharr(img_gray, ygrad0, CV_16S, 0, 1, 3);
    convertScaleAbs(xgrad0, xgrad0);
    convertScaleAbs(ygrad0, ygrad0);
    imshow("Scharr_xgrad", xgrad0);
    imshow("Scharr_ygrad", ygrad0);

    Sobel(img_gray, xgrad1, CV_16S, 1, 0, 3);
    Sobel(img_gray, ygrad1, CV_16S, 0, 1, 3);
    convertScaleAbs(xgrad1, xgrad1);
    convertScaleAbs(ygrad1, ygrad1);
    imshow("Sobel_xgrad", xgrad1);
    imshow("Sobel_ygrad", ygrad1);

    //Laplace利用Sobel算子的运算，它通过Sobel算子运算出图像在x方向和y方向的导数，来得到我们载入图像的拉普拉斯变换结果。
    Laplacian(img_gray, laplace, CV_16S, 3);
    convertScaleAbs(laplace, laplace);
    imshow("Laplacian", laplace);

    cv::waitKey(0);
    return 0;
}